
from apps.common.base.serializers import *
from apps.interface.advert.models import *

class AdvertBaseSerializer(BaseSerializer):

    class Meta:
        model = Advert
        fields = "__all__"

class AdvertModelSerializer(BaseSerializer):

    fileType = serializers.SerializerMethodField()
    def get_fileType(self, obj):
        imgList = ['.jpg', '.png', '.gif', '.jpeg', '.JPG', '.PNG', '.GIF', '.JPEG']
        vodios = ['.mp4', '.avi', '.wmv', '.flv', '.rmvb']
        flag = False
        for item in vodios:
            if obj.coverUrl.find(item) != -1:
                flag = True

        if flag == True:
            return 'video'
        else:
            return 'image'


    class Meta:
        model = Advert
        fields = "__all__"